home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / mail110 / init.c < prev    next >
C/C++ Source or Header  |  1994-02-25  |  6KB  |  190 lines

  1. //=========================================================
  2. //
  3. //      void init(char *version)
  4. //
  5. //      Open mailer.rc (which must be in the current dir)
  6. //      and setup the global variables for:
  7. //      
  8. //      mailpath, mqueuepath, sequence, user, host, mail, reply,
  9. //      name, edit, from, sig.
  10. //
  11. //      exit program if mailer.rc cannot be opened or the file
  12. //      either cannot be read or does not contain the required
  13. //      data.
  14. //
  15. //=========================================================
  16.  
  17. // $Id: init.c,v 1.5 1994/02/25 13:34:54 gbj Exp user $
  18.  
  19. /*
  20. $Log: init.c,v $
  21.  * Revision 1.5  1994/02/25  13:34:54  gbj
  22.  * Tidy-up.
  23.  *
  24.  * Revision 1.4  1994/02/20  19:14:04  gbj
  25.  * Added mail aliasing.
  26.  *
  27.  * Revision 1.3  1994/02/14  23:36:52  gbj
  28.  * Incorporated changes for Alec Jones's outgoing mail log.
  29.  *
  30.  * Revision 1.2  1994/02/08  23:32:02  gbj
  31.  * First public release.
  32.  *
  33.  * Revision 1.1  1994/02/08  03:15:10  gbj
  34.  * Initial revision
  35.  *
  36. */
  37.  
  38. #include "mailer.h"
  39.  
  40. void init(char *version)
  41. {
  42.  
  43.         char *buf, *bp, *f1, *f2;
  44.         FILE *rc;
  45.         int err;
  46.         char logfile[128];
  47.  
  48.         fprintf(stderr, "%s [G B JUDD]\n\n", version);
  49.  
  50.         err=0;
  51.         rc=fopen("mailer.rc", "r");
  52.         if (rc == NULL)
  53.         {
  54.                 fprintf(stderr, "\ninit: cannot open mailer.rc\n");
  55.                 exit(1);
  56.         }       
  57.         buf=(char*)malloc(128);
  58.         if (buf == NULL)
  59.         {
  60.                 fprintf(stderr, 
  61.                         "\ninit: cannot allocate 128 bytes for buffer\n");
  62.                 fclose(rc);
  63.                 exit(1);
  64.         }
  65.         
  66.         bp=fgets(buf, 127, rc);
  67.         if (bp == NULL)
  68.         {
  69.                 fprintf(stderr, "\ninit: mailer.rc is empty\n");
  70.                 exit(1);
  71.         }
  72.         *mailpath='\0';
  73.         *mqueuepath='\0';
  74.         *sequence='\0';
  75.         *mbox='\0';
  76.         *host='\0';
  77.         *reply='\0';
  78.         *from='\0';
  79.         *name='\0';
  80.         *edit='\0';
  81.         *mail='\0';
  82.         *sig='\0';
  83.         *logfile='\0';
  84.         *log='\0';
  85.         *alias='\0';
  86.         
  87.         while (bp != NULL)
  88.         {
  89.                 if (buf[0] != '#' && buf[0] != ' ' 
  90.                         && buf[0] != '\n')      // comment
  91.                 {
  92.                         f1=strtok(buf, "=");
  93.                         f2=strtok(NULL, "\n");
  94.                         if (strcmp(f1, "user") == 0)
  95.                                 strcpy(user, f2);
  96.                         else if (strcmp(f1, "host") == 0)
  97.                                 strcpy(host, f2);
  98.                         else if (strcmp(f1, "mail") == 0)
  99.                                 strcpy(mail, f2);
  100.                         else if (strcmp(f1, "reply") == 0)
  101.                                 strcpy(reply, f2);
  102.                         else if (strcmp(f1, "name") == 0)
  103.                                 strcpy(name, f2);
  104.                         else if (strcmp(f1, "edit") == 0)
  105.                                 strcpy(edit, f2);
  106.                         else if (strcmp(f1, "sig") == 0)
  107.                                 strcpy(sig, f2);
  108.                         else if (strcmp(f1, "log") == 0)
  109.                                 strcpy(logfile, f2);
  110.                         else if (strcmp(f1, "alias") == 0)
  111.                                 strcpy(alias, f2);
  112.                 }
  113.                 bp=fgets(buf, 127, rc);
  114.         }
  115.         
  116.         if (!*mail)
  117.         {
  118.                 fprintf(stderr, "\ninit: no <mail> in mailer.rc\n");
  119.                 err=1;
  120.         }
  121.         if (!*user)
  122.         {
  123.                 fprintf(stderr, "\ninit: no <user> in mailer.rc\n");
  124.                 err=1;
  125.         }
  126.         if(!*host)
  127.         {
  128.                 fprintf(stderr, "\ninit: no <host> in mailer.rc\n");
  129.                 err=1;
  130.         }
  131.         if(!*reply)
  132.         {
  133.                 fprintf(stderr, "\ninit: no <reply> in mailer.rc\n");
  134.                 err=1;
  135.         }
  136.         if(!*edit)
  137.         {
  138.                 fprintf(stderr, "\ninit: no <edit> in mailer.rc\n");
  139.                 err=1;
  140.         }
  141.         
  142.         if (err)
  143.         {
  144.                 free(buf);
  145.                 fclose(rc);
  146.                 exit(1);
  147.         }
  148.         
  149.         strcpy(mailpath, mail);
  150.         strcat(mailpath, "\\mail");
  151.         strcpy(mqueuepath, mail);
  152.         strcat(mqueuepath, "\\mqueue");
  153.         strcpy(sequence, mqueuepath);
  154.         strcat(sequence, "\\sequence.seq");
  155.         strcpy(from, user);
  156.         strcat(from, "@");
  157.         strcat(from, host);
  158.         if (*logfile)
  159.         {
  160.                 strcpy(log, mail);
  161.                 strcat(log, "\\mail\\");
  162.                 strcat(log, logfile);
  163.         }
  164.         if (*name)
  165.         {
  166.                 strcat(from, " (");
  167.                 strcat(from, name);
  168.                 strcat(from, ")");
  169.         }
  170.  
  171. //      fprintf(stderr, "user       %s\n", user);
  172. //      fprintf(stderr, "host       %s\n", host);
  173. //      fprintf(stderr, "mail       %s\n", mail);
  174. //      fprintf(stderr, "reply      %s\n", reply);
  175. //      fprintf(stderr, "name       %s\n", name);
  176. //      fprintf(stderr, "edit       %s\n\n", edit);
  177. //      fprintf(stderr, "from       %s\n", from);
  178. //  fprintf(stderr, "sig        %s\n", sig);
  179. //      fprintf(stderr, "mailpath   %s\n", mailpath);
  180. //      fprintf(stderr, "mqueuepath %s\n", mqueuepath);
  181. //      fprintf(stderr, "sequence   %s\n", sequence);
  182. //      fprintf(stderr, "log        %s\n", log);
  183. //      fprintf(stderr, "alias      %s\n", alias);
  184. //      fprintf(stderr, "\n");  
  185.         free(buf);
  186.         fclose(rc);
  187.         return;
  188.         
  189. }
  190.